package labels

import (
	"GinTemplate/internal/databases/mysql"
	"GinTemplate/internal/models"
)

func GetAll() (items []models.Label, total int64, err error) {
	result := mysql.DB.Debug().Find(&items)
	return items, result.RowsAffected, result.Error
}

func GetLabelById(id int) (label models.Label, err error) {
	result := mysql.DB.Debug().Find(&label, id)
	return label, result.Error
}

func Add(label *models.Label) (err error) {
	result := mysql.DB.Debug().Create(&label)
	return result.Error
}

func Delete(id int) (err error) {
	result := mysql.DB.Debug().Delete(&models.Label{}, id)
	return result.Error
}

func Update(id int, label *models.UpdateLabel) (err error) {
	result := mysql.DB.Debug().Where("id = ?", id).Save(&label)
	return result.Error
}
